package com.itqf.demo01;

import com.itqf.job.MyJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/11/19
 * @Time: 上午10:38
 */
public class TestQuartz {
    public  static  void  main(String[]args) throws  Exception{
        //1,创建调度器
        Scheduler scheduler = new StdSchedulerFactory().getScheduler();

        //2,创建JobDetail 描述任务
        JobDetail jobDetail = JobBuilder.newJob(MyJob.class)
                .withIdentity("myJob","myGroup")
                .build();

        //3,触发器  Trigger
        SimpleTrigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("myTrigger","myGroup")
                .withSchedule(SimpleScheduleBuilder
                        .simpleSchedule() //构建一个简单触发器
                       // .repeatForever() //永不停歇
                        .withRepeatCount(5)  //重复执行的次数
                        .withIntervalInSeconds(1))//间隔时间
                .startNow()
                .build();

        //4,注册触发器和任务
        scheduler.scheduleJob(jobDetail,trigger);

        //5,开启任务
        scheduler.start();



    }
}
